<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Lookup_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    public function getResult($name)
    {
        return $this->db->query('SELECT * FROM app_lookup WHERE description LIKE "'.$name.'"')->result();
    }

    public function getLookUp($name)
    {
        $this->db->where('lookup_type',$name);
        return $this->db->get('app_lookup')->result();
    }

    public function getLookUpValues($name)
    {
        $this->db->where('lookup_type',$name);
        return $this->db->get('app_lookup_values')->result();
    }

    public function storeLookUp($data)
    {
        $this->db->query("call app_lookup_ins(?,?,?,?,@err,@msg,@code)", $data);
        $que = $this->db->query("SELECT @err as err,@msg as msg,@code as code");
        $msg;
        $err;
        $code;
        foreach ($que->result() as $keys) {
            $err = $keys->err;
            $msg = $keys->msg;
            $code = $keys->code;
        }
        $arr = array(
            'err' => $err,
            'msg' => $msg,
            'code' => $code,
        );
        echo json_encode($arr);
    }

    public function putLookUp($data)
    {
        $this->db->query("call app_lookup_upd(?,?,?,?,@err,@msg)", $data);
        $que = $this->db->query("SELECT @err as err,@msg as msg");
        $msg;
        $err;
        foreach ($que->result() as $keys) {
            $err = $keys->err;
            $msg = $keys->msg;
        }
        $arr = array(
            'err' => $err,
            'msg' => $msg,
        );
        echo json_encode($arr);
    }

    public function storeLookUpValues($data)
    {
        $this->db->query("call app_lookup_values_ins(?,?,?,?,?,?,@err,@msg)", $data);
        $que = $this->db->query("SELECT @err as err, @msg as msg");
        $msg;
        $err;
        foreach ($que->result() as $keys) {
            $err = $keys->err;
            $msg = $keys->msg;
        }
        $arr = array(
            'err' => $err,
            'msg' => $msg,
        );
        echo json_encode($arr);
    }

    public function putLookUpValues($data)
    {
        $this->db->query("call app_lookup_values_upd(?,?,?,?,?,?,@err,@msg)", $data);
        $que = $this->db->query("SELECT @err as err,@msg as msg");
        $msg;
        $err;
        foreach ($que->result() as $keys) {
            $err = $keys->err;
            $msg = $keys->msg;
        }
        $arr = array(
            'err' => $err,
            'msg' => $msg,
        );
        echo json_encode($arr);
    }
}